var gameContentJS;
var gameContainerJS;
var gameUtilJS;
var gameContentID = "gameContent";
var gameContainerID = "gameContainer";
var gameUtilID;


var detect = navigator.userAgent.toLowerCase();
var isMac = (detect.indexOf('macintosh') != -1);
var isWin = (detect.indexOf('windows') != -1);
var isLin = (detect.indexOf('linux') != -1);

// Is Internet Explorer
var isIE = (detect.indexOf('msie 6.0') != -1 || detect.indexOf('msie 7.0') != -1 || detect.indexOf('msie 8.0') != -1);

// Is Firefox
var isMZ2 = (detect.indexOf('firefox/2.0') != -1);
var isMZ3 = (detect.indexOf('firefox/3.0') != -1 || detect.indexOf('minefield/3.0') != -1);
var isMZ = (isMZ2 || isMZ3);

// Is Firefox Mac
var isFM = (isMZ && isMac);

// Is Safari
var isSF3 = (detect.indexOf('safari/523') != -1 || detect.indexOf('safari/525') != -1) && isMac;

var prevWidth;
var prevHeight;

function initLibrary()
{
	if (isIE)
		IELoad();
	else if (isFM)
		FMLoad();
	else if (isMZ)
		MZLoad();
	else if (isSF3)
		SFLoad();
		
	prevWidth = GetWidth();
	prevHeight = GetHeight();
}

/**
 * Function Return the browser type as a String
 */
function GetBrowserType()
{
	if (isIE)
		return "IE";
	if (isMac && isMZ)
		return "FirefoxMac";
	if (isMZ)
		return "FirefoxWindows";
	if (isSF3)
		return "Safari";
	return "Unknown";
}

function ChangeGameSize(width, height)
{
	if (isIE)
		IEChangeGameSize(width, height);
	else if (isFM)
		FMChangeGameSize(width, height);
	else if (isMZ)
		MZChangeGameSize(width, height);
	else if (isSF3)
		SFChangeGameSize(width, height);
}

/** 
 * Function to give the focus back to the DIV in the webpage
 * This is used to allow the listening of the keyboard.
 */
function ReturnFocusToJS()
{
	if (isIE)
		IEReturnFocusToJS();
	else if (isFM)
		return  FMReturnFocusToJS();
	else if (isMZ)
		return  MZReturnFocusToJS();
	else if (isSF3)
		return  SFReturnFocusToJS();
}

/**
 * Function to give back the focus to the CMM application
 */
 
function ReturnFocusToGame()
{
	if (isIE)
		IEReturnFocusToGame();
	else if (isFM)
		FMReturnFocusToGame();
	else if (isMZ)
		MZReturnFocusToGame();
	else if (isSF3)
		SFReturnFocusToGame();
}

/** Debug **/

function FocusDebugging()
{
	if (isIE)
		IEFocusDebugging()
	else if (isFM)
		FMFocusDebugging()
}

function GetWidth()
{
	var x = 0;
    if (window.innerWidth)
	{
		x = window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		x = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		x = document.body.clientWidth;
	}
	return x;
}
       
function GetHeight()
{
	var y = 0;
	if (window.innerHeight)
	{
		y = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		y = document.documentElement.clientHeight;
	} 
	else if (document.body)
	{
		y = document.body.clientHeight;
	}
	return y;
}